﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ICDA.Web.Helper
{
    public class DatetTimeHelper
    {
        public DateTime weekStartDate { get; set; }
        public DateTime weekEndDate { get; set; }

        public DateTime MonthStartDate 
        { 
            get 
            { 
                return new DateTime(CurrentDateTime.Year, CurrentDateTime.Month, 1); 
            } 
        }
        public DateTime MonthEndDate 
        { 
            get 
            { 
                return new DateTime(CurrentDateTime.Year, CurrentDateTime.Month, 1).AddMonths(1).AddDays(-1); 
            } 
        }
        public DateTime CurrentDateTime { get; set; }
        public int CurrentYear { get; set; }
        public int TotalDaysInMonth { get { return DateTime.DaysInMonth(CurrentDateTime.Year, CurrentDateTime.Month);}}
        public int NextMonth
        {
            get
            {
                if (CurrentDateTime.Month == 12)
                {
                    return 1;
                }
                else
                {
                    return CurrentDateTime.Month + 1;
                }
            }
        }
        public int PreviousMonth
        {
            get
            {
                if (CurrentDateTime.Month == 1)
                {
                    return 12;
                }
                else
                {
                    return CurrentDateTime.Month + 1;
                }
            }
        }
        public DateTime NextYearDate
        {
            get
            {
                if (CurrentDateTime.Month >= 1 || CurrentDateTime.Month < 12)
                {
                    return CurrentDateTime.AddMonths(1);
                }
                else
                {
                    return new DateTime(CurrentDateTime.AddYears(1).Year, CurrentDateTime.AddMonths(1).Month, CurrentDateTime.Day);
                }
            }
        }
        public DateTime PreviousYearDate
        {
            get
            {
                if (CurrentDateTime.Month > 1 || CurrentDateTime.Month >= 12)
                {
                    return CurrentDateTime.AddMonths(-1);
                }
                else
                {
                    return new DateTime(CurrentDateTime.AddYears(-1).Year, CurrentDateTime.AddMonths(-1).Month, CurrentDateTime.Day);
                }
            }
        }
        
        public DatetTimeHelper()
        {
            int days = DateTime.Now.DayOfWeek - DayOfWeek.Monday;
            this.weekStartDate = DateTime.Now.AddDays(-days);
            this.weekEndDate = weekStartDate.AddDays(6);
        }
        public DatetTimeHelper(DateTime currentdate)
        {
            this.CurrentDateTime = currentdate;
        }
        public DateTime FormatDateTime(DateTime dateTime)
        {
            return Convert.ToDateTime(dateTime.ToString("d"));
        }
        public DateTime FormatDate(string dateTime)
        {
            return DateTime.ParseExact(dateTime, "d", System.Globalization.CultureInfo.InvariantCulture);// Convert.ToDateTime(dateTime);
        }
        public bool DateCompareForGreaterEqual(DateTime date1, DateTime date2)
        {
            if (date1.Day >= date2.Day && date1.Month >= date2.Month && date1.Year >= date2.Year)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool DateCompareForLessEqual(DateTime date1, DateTime date2)
        {
            if (date1.Day <= date2.Day && date1.Month <= date2.Month && date1.Year <= date2.Year)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
       
    }
}